<!-- 营收结算月 -->
<template>
    <div class="boxwrapper">
        <el-form :inline="true" :model="ruleForm" class="demo-form-inline">
            <el-form-item label="报表名称：">
                <el-input placeholder="请输入报表名称" v-model.trim="ruleForm.reportFormName" maxlength="20" size="small"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="success"  @click="searchList"  id="monitorEnter" size="small">查询</el-button>
                <el-button type="primary"  @click="generateReport" size="small">生成报表</el-button>
            </el-form-item>
        </el-form>

        <el-table :data="tableData" border style="width: 100%">
            <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
            <el-table-column label="报表名称" prop="reportFormName" align="center"></el-table-column>
            <el-table-column label="月份" prop="month" align="center"></el-table-column>
            <el-table-column label="营收佣金（元）"  prop="revenueCommission" align="center">
                <template slot-scope="scope">{{scope.row.revenueCommission | initCash}}</template>
            </el-table-column>
           <!--  <el-table-column label="计提点数%" prop="relList" :formatter="initrel"  align="center"></el-table-column> -->
            <el-table-column label="营收分配明细(元)" align="center">
                 <template slot-scope="scope"><el-button type="text" @click="detailshander(scope.row)">{{scope.row.revenueCommissionAllot | initCash}}</el-button></template>
            </el-table-column>
            <el-table-column label="成交详情" align="center">
                <template slot-scope="scope"><el-button type="text" @click="seehander(scope.row)">查看</el-button></template>
            </el-table-column>
        </el-table>

        <div class="pagebar">
          <el-pagination
            background
            layout="total, sizes, prev, pager, next"
            :current-page.sync="ruleForm.pageNum"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="ruleForm.pageSize"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :total="totalSize">
          </el-pagination>
        </div>

        <el-dialog
        title=""
        :visible.sync="centerDialogVisible"
        width="50%"
        center>
            <el-table :data="tableData2" border style="width: 100%">
               <el-table-column label="开发商名称" prop="developerName" align="center"></el-table-column>
               <el-table-column label="营收佣金（元)" prop="houseNum" align="center">
                   <template slot-scope="scope">
                       {{scope.row.calBase | initCash}}
                   </template>
               </el-table-column>
               <el-table-column label="计提点数%" prop="calProportion" align="center">
                   <template slot-scope="scope">
                    {{scope.row.calProportion}}
                   </template>
               </el-table-column>
               <el-table-column label="营收分配明细（元）" prop="revenueAmount" align="center">
                   <template slot-scope="scope">
                       {{scope.row.revenueAmount | initCash}}
                   </template>
               </el-table-column>
            </el-table>
            <div style="margin-top: 20px;">
                <el-pagination
                  background
                  layout="total, sizes, prev, pager, next"
                  :current-page.sync="ruleForm.pageNum"
                  :page-sizes="[10, 20, 30, 40]"
                  :page-size="ruleForm.pageSize"
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :total="totalSize2">
                </el-pagination>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="centerDialogVisible = false">关闭</el-button>
            </span>
        </el-dialog>

    </div>
</template>
<script>
    import api from '@/api/apiPath'
    export default {
        name: 'revenueSettlementMonth',
        title:'营收结算',
        data () {
            return {
                ruleForm:{
                    reportFormName:undefined,
                    pageNum: 0,
                    pageSize: 10,
                },
                ruleForm2:{
                    reportMonthId:undefined,
                    pageNum: 0,
                    pageSize: 10,
                },
                totalSize:0,
                totalSize2:0,
                centerDialogVisible:false,
                tableData:[],
                tableData2:[],
            }
        },
        filters:{
            initCash(cellValue){
                if(cellValue !== 0){
                    return cellValue.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");
                }
                if(cellValue == 0){
                    return "0.00"
                }
            },
        },
        methods:{
            initrel(row, column, cellValue, index){
                if (cellValue.length>0) {
                    let str =""
                    cellValue.forEach((item,index)=>{
                        if (index<3) {
                            str += item.developerName+': '+item.calProportion+'\n'
                        }else {
                            str+= '...'
                        }
                    })
                    return str
                }else {
                    return "———"
                }
            },
            handleCurrentChange(){
                this.getlist()
            },
            handleSizeChange(val){
                this.ruleForm.pageSize = val
                this.getlist();
            },
            getlist(){
                this.axios.post(api.GETREMONTHLIST,this.ruleForm).then((res) => {
                  if (res && res.data.code == 200) {
                        this.tableData = res.data.data.data
                        this.totalSize = res.data.data.total
                   }
                })
            },
            generateReport(){
                this.$router.push({path:'/revenueSettlementMonthReport'})
            },
            searchList(){
                this.ruleForm.pageNum = 1
                this.getlist()
            },
            //查询营收明细
            detailshander(row){
                this.centerDialogVisible = true
                this.ruleForm2.reportMonthId = row.id
                this.axios.post(api.GETREMONTHLISTPOPUP,this.ruleForm2).then((res) => {
                  if (res && res.data.code == 200) {
                        this.tableData2 = res.data.data.data
                        this.totalSize2 = res.data.data.total
                   }
                })
            },
            seehander(row){
                this.$router.push({path:'/revenueSettlementMonthDetail',query:{standardId: row.id}})
            }
        },
        activated(){
            this.searchList()
        },
        created(){
            this.getlist()
        }
    }


</script>


<style lang="stylus">

    .boxwrapper .el-table .cell {
         text-align: center;
         white-space: pre-line !important;
     }
</style>
